package chat.servlet;

import java.io.IOException;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import chat.single.MsgSing;
import chat.user.UserBean;

public class ChatViewAction extends HttpServlet{
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String path = req.getContextPath();
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		
		String umsg=req.getParameter("msg");
		String umsg1 = new String(umsg.getBytes("iso-8859-1"), "utf-8");
		System.out.println(umsg1);
		Object nameobj=	req.getSession().getAttribute("name");
		String name=nameobj==null?"":nameobj.toString();
		
		UserBean u=new UserBean(name);
		
		MsgSing msgobj=MsgSing.getIns();
		msgobj.addMsg(u,umsg);
		resp.sendRedirect(""+path+"/Chatview");
		
	}
}
